*Figure 9B: Number of important provisions by country. 


*Create Shapefile
spshape2dta "WB_countries_Admin0_10m/WB_countries_Admin0_10m", replace saving(world)

*Initial cleaning to prepare for fuzzy match
use world, clear
keep _ID _CX FORMAL_EN Shape_* ECONOMY INCOME_GRP CONTINENT SUBREGION
duplicates drop FORMAL_EN, force
drop if FORMAL_EN == ""
gen FORMAL_EN_clean = ""
replace FORMAL_EN_clean = subinstr(FORMAL_EN,"Republic", "", .)
replace FORMAL_EN_clean = subinstr(FORMAL_EN_clean,"Kingdom", "", .)
replace FORMAL_EN_clean = subinstr(FORMAL_EN_clean," of ", "", .)
sort _ID

*Manual Adjustment for Greece (names are completely different so the fuzzy match will not even consider it a candidate)
replace FORMAL_EN_clean = "Greece" if FORMAL_EN_clean == "Hellenic "

tempfile prev
save `prev', replace
*Fuzzy Match with World Bank coordinates data
matchit _ID FORMAL_EN_clean using "Data_mapping_country_merged.dta", idu(id) txtu(country) override threshold(0.2)
merge m:1 _ID using `prev'
keep if _merge == 3
drop _merge


gsort _ID -similscore
bysort _ID: gen val = _n

*Generate keep variable and futher cleaning. 
gen keep = .
replace keep = 1 if val == 1 & similscore == 1
sort _ID
replace country=strtrim(country)
replace FORMAL_EN_clean=strtrim(FORMAL_EN_clean)


*Manually match countries that have different names (failed the fuzzy match)
replace keep = 1 if country == "Argentina" & FORMAL_EN_clean == "Argentine"
replace keep = 1 if country == "China" & FORMAL_EN_clean == "People's China"
replace keep = 1 if country == "Israel" & FORMAL_EN_clean == "StateIsrael"
replace keep = 1 if country == "Lebanon" & FORMAL_EN_clean == "Lebanese"
replace keep = 1 if country == "Ethiopia" & FORMAL_EN_clean == "Federal Democratic Ethiopia"
replace keep = 1 if country == "Somalia" & FORMAL_EN_clean == "Federal Somalia"
replace keep = 1 if country == "Pakistan" & FORMAL_EN_clean == "Islamic Pakistan"
replace keep = 1 if country == "Tanzania" & FORMAL_EN_clean == "United Tanzania"
replace keep = 1 if country == "Syria" & FORMAL_EN_clean == "Syrian Arab"
replace keep = 1 if country == "Guyana" & FORMAL_EN_clean == "Co-operative Guyana"
replace keep = 1 if country == "Morocco" & FORMAL_EN_clean == "KingdomMorocco"
replace keep = 1 if country == "Argentina" & FORMAL_EN_clean == "Argentine"
replace keep = 1 if country == "Democratic Republic of the Congo" & FORMAL_EN_clean == "Democratic the Congo"
replace keep = 1 if country == "Bhutan" & FORMAL_EN_clean == "KingdomBhutan"
replace keep = 1 if country == "Oman" & FORMAL_EN_clean == "SultanateOman"
replace keep = 1 if country == "Brazil" & FORMAL_EN_clean == "Federative Brazil"
replace keep = 1 if country == "Russia" & FORMAL_EN_clean == "Russian Federation"
replace keep = 1 if country == "Czech Republic" & FORMAL_EN_clean == "Czech"
replace keep = 1 if country == "Germany" & FORMAL_EN_clean == "Federal Germany"
replace keep = 1 if country == "Norway" & FORMAL_EN_clean == "KingdomNorway"
replace keep = 1 if country == "Sweden" & FORMAL_EN_clean == "KingdomSweden"
replace keep = 1 if country == "Vietnam" & FORMAL_EN_clean == "Socialist Vietnam"
replace keep = 1 if country == "Cambodia" & FORMAL_EN_clean == "KingdomCambodia"
replace keep = 1 if country == "Luxembourg" & FORMAL_EN_clean == "Grand DuchyLuxembourg"
replace keep = 1 if country == "Belgium" & FORMAL_EN_clean == "KingdomBelgium"
replace keep = 1 if country == "Argentina" & FORMAL_EN_clean == "Argentine"
replace keep = 1 if country == "Kyrgyz Republic" & FORMAL_EN_clean == "Kyrgyz"
replace keep = 1 if country == "Slovak Republic" & FORMAL_EN_clean == "Slovak"
replace keep = 1 if country == "Central African Republic" & FORMAL_EN_clean == "Central African"
replace keep = 1 if country == "Eritrea" & FORMAL_EN_clean == "StateEritrea"
replace keep = 1 if country == "Italy" & FORMAL_EN_clean == "Italian"
replace keep = 1 if country == "Iran" & FORMAL_EN_clean == "Islamic Iran"
replace keep = 1 if country == "Liechtenstein" & FORMAL_EN_clean == "PrincipalityLiechtenstein"
replace keep = 1 if country == "Nigeria" & FORMAL_EN_clean == "Federal Nigeria"
replace keep = 1 if country == "Angola" & FORMAL_EN_clean == "People's Angola"
replace keep = 1 if country == "Qatar" & FORMAL_EN_clean == "StateQatar"
replace keep = 1 if country == "Dominican Republic" & FORMAL_EN_clean == "Dominican"
replace keep = 1 if country == "Kuwait" & FORMAL_EN_clean == "StateKuwait"
replace keep = 1 if country == "Monaco" & FORMAL_EN_clean == "PrincipalityMonaco"
replace keep = 1 if country == "Eswatini" & FORMAL_EN_clean == "eSwatini"
replace keep = 1 if country == "Myanmar" & FORMAL_EN_clean == "the UnionMyanmar"
replace keep = 1 if country == "Bangladesh" & FORMAL_EN_clean == "Peopl's Bangladesh"
replace keep = 1 if country == "Andorra" & FORMAL_EN_clean == "PrincipalityAndorra"
replace keep = 1 if country == "Afghanistan" & FORMAL_EN_clean == "Islamic StateAfghanistan"
replace keep = 1 if country == "Portugal" & FORMAL_EN_clean == "Portuguese"
replace keep = 1 if country == "Argentina" & FORMAL_EN_clean == "Argentine"
replace keep = 1 if country == "Gabon" & FORMAL_EN_clean == "Gabonese"
replace keep = 1 if country == "Togo" & FORMAL_EN_clean == "Togolese"
replace keep = 1 if country == "Argentina" & FORMAL_EN_clean == "Argentine"
replace keep = 1 if country == "United States" & FORMAL_EN_clean == "United StatesAmerica"
replace keep = 1 if country == "Papa New Guinea" & FORMAL_EN_clean == "Independent StatePapua New Guinea"
replace keep = 1 if country == "Egypt" & FORMAL_EN_clean == "Arab Egypt"
replace keep = 1 if country == "Mauritania" & FORMAL_EN_clean == "Islamic Mauritania"
replace keep = 1 if country == "Gambia" & FORMAL_EN_clean == "the Gambia"
replace keep = 1 if country == "Australia" & FORMAL_EN_clean == "CommonwealthAustralia"
replace keep = 1 if country == "Philippines" & FORMAL_EN_clean == "the Philippines"
replace keep = 1 if country == "Bahamas" & FORMAL_EN_clean == "Commonwealththe Bahamas"
replace keep = 1 if country == "Marshall Islands" & FORMAL_EN_clean == "the Marshall Islands"
replace keep = 1 if country == "Saint Kitts and Nevis" & FORMAL_EN_clean == "FederationSaint Kitts and Nevis"
replace keep = 1 if country == "Comoros" & FORMAL_EN_clean == "Unionthe Comoros"
replace keep = 1 if country == "Sao Tome and Principe" & FORMAL_EN_clean == "Democratic São Tomé and Principe"
replace keep = 1 if country == "Cape Verde" & FORMAL_EN_clean == "Cabo Verde"
replace keep = 1 if country == "Micronesia" & FORMAL_EN_clean == "Federated StatesMicronesia"
replace keep = 1 if country == "Cape Verde" & FORMAL_EN_clean == "Cabo Verde"
replace keep = 1 if country == "Netherlands" & FORMAL_EN_clean == "the Netherlands"
replace keep = 1 if country == "Congo" & FORMAL_EN_clean == "the Congo"
replace keep = 1 if country == "Uruguay" & FORMAL_EN_clean == "Oriental Uruguay"
replace keep = 1 if country == "North Macedonia" & FORMAL_EN_clean == "Former Yugoslav Macedonia"
replace keep = 1 if country == "Sudan" & FORMAL_EN_clean == "the Sudan"
replace keep = 1 if country == "North Macedonia" & FORMAL_EN_clean == "Former Yugoslav Macedonia"
replace keep = 1 if country == "Timor" & FORMAL_EN_clean == "Democratic Timor-Leste"
replace keep = 1 if country == "Brunei" & FORMAL_EN_clean == "Negara Brunei Darussalam"
replace keep = 1 if country == "North Macedonia" & FORMAL_EN_clean == "Former Yugoslav Macedonia"
replace keep = 1 if country == "Bangladesh" & FORMAL_EN_clean == "People's Bangladesh"
replace keep = 1 if country == "Jordan" & FORMAL_EN_clean == "Hashemite Jordan"
replace keep = 1 if country == "Venezuela" & FORMAL_EN_clean == "Bolivarian Venezuela"
replace keep = 1 if country == "Dominica" & FORMAL_EN_clean == "CommonwealthDominica"
replace keep = 1 if country == "Papua New Guinea" & FORMAL_EN_clean == "Independent StatePapua New Guinea"
replace keep = 1 if country == "South Korea" & FORMAL_EN_clean == "Korea"
replace keep = 1 if country == "North Korea" & FORMAL_EN_clean == "Democratic People's Korea"
replace keep = 1 if country == "Bolivia" & FORMAL_EN_clean == "Plurinational StateBolivia"
replace keep = 1 if country == "France" & FORMAL_EN_clean == "French"
replace keep = 1 if country == "Laos" & FORMAL_EN_clean == "Lao People's Democratic"
replace keep = 1 if country == "United Kingdom" & FORMAL_EN_clean == "United Great Britain and Northern Ireland"
replace keep = 1 if country == "Greece" & FORMAL_EN_clean == "Hellenic"
replace keep = 1 if country == "Switzerland" & FORMAL_EN_clean == "Swiss Confederation"
replace keep = 1 if country == "Cote d'Ivoire" & FORMAL_EN_clean == "Ivory Coast"
replace keep = 1 if country == "Algeria" & FORMAL_EN_clean == "People's Democratic Algeria"
replace keep = 1 if country == "Mexico" & FORMAL_EN_clean == "United Mexican States"
replace keep = 1 if country == "Yemen Arab Republic" & FORMAL_EN_clean == "Yemen"
replace keep = 1 if country == "Sri Lanka" & FORMAL_EN_clean == "Democratic Socialist Sri Lanka"
replace keep = 1 if country == "Samoa" & FORMAL_EN_clean == "Independent StateSamoa"

gsort id -similscore
bysort id: gen already_good = 1 if keep == 1
sort id keep
by id: replace already_good = already_good[_n-1] if already_good == .
drop if already_good == 1 & keep != 1
keep if keep == 1
sort country
keep country ECONOMY INCOME_GRP CONTINENT SUBREGION
tempfile temporary
save `temporary', replace

*Merge the World Bank/CCP crosswalk with the World Bank Coordinates
use "Data_CoreProvisions_240423.dta", clear
ren origin country
// ren _merge _mergeprev
merge m:1 country using `temporary'
drop if _merge != 3
drop _merge



**************Figure 9B**************

keep if year >= 1950 & year <= 2020

replace CONTINENT = "Asia" if country == "Maldives"
replace CONTINENT = "Africa" if country == "Mauritius" | country == "Seychelles"
collapse (mean) total_present, by(year CONTINENT)
twoway line total_present year, by(CONTINENT, ixaxes note("") title("")) xtitle("Year") ytitle("Number of Important Provisions") xlabel(1950(20)2025) xlabel(1950 1970 1990 2010 2020)
graph export "Figure_9B.pdf", replace



